/**
 * 作者:hanbo
 * 日期:2018/12/149:45
 * 描述:多段线绘制程序
 */
import {VectorBrush} from "./VectorBrush";


export class PolylinesBrush extends VectorBrush {
    constructor(webGL) {
        super(webGL)
    }


    /**
     * 批量绘制线
     * @param float32Array {Float32Array} 缓冲区数组
     * @param index {Number[]} 每条线由几段组成
     * @param n {Number} 线数量
     */
    drawLines(float32Array, index) {
        this._verticesColors = float32Array;
        this._index = index;
    }

    draw(projection) {
        super.draw(projection);
        this.flushData(this._verticesColors);
        this._compile();
    }

    /**
     * 批量绘制线

     */
    _compile() {
        let currentIndex = 0;
        for (let i = 0; i < this._index.length; i++) {
            this._webGL.drawArrays(this._webGL.TRIANGLE_STRIP, currentIndex, this._index[i]);
            currentIndex += this._index[i];
        }
    }
}